package jin.si.com.xc;

/**
 * @description:
 * @ClassName MyRunnable
 * @Author MT
 * @Date 2021/7/2 14:52
 **/
public class MyRunnable implements Runnable{

    //同一个对象不需要设置静态
    private  int number=300;

    @Override
    public void run() {


        //获取线程的名字 Thread.currentThread().getName()
        while (true){
            try {
                //设置线程睡眠
                System.out.println(Thread.currentThread().getName()+"睡眠了");
                Thread.sleep(30);
            } catch (InterruptedException e) {
                System.out.println(Thread.currentThread().getName()+"被打扰了");
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"睡醒了");
             if(number>0){
                System.out.println(Thread.currentThread().getName()+":"+number);
                Thread.yield();//线程礼让
                number--;
            }else {
                break;
            }
        }

       /*for (int a=0;a<30;a++){
           System.out.println(Thread.currentThread().getName()+":"+a);
       }*/




    }



}
